package sqlanalysisgui.editor;

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.layouts.LayoutAlgorithm;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm;

import sqlanalysisgui.view.model.provider.GraphNodeContentProvider;
import sqlanalysisgui.view.model.provider.GraphNodeLabelProvider;
import sqlanalysisgui.view.model.provider.GraphNodeModelContentProvider;

public class GraphNodeTestEditor extends EditorPart {
	public static final String ID = "sqlanalysisgui.editor.GraphNodeTestEditor"; //$NON-NLS-1$
	private Logger logger = Logger.getLogger(this.getClass());
	private GraphViewer viewer;
	private DashboardTableInput input;

	public GraphNodeTestEditor() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
		viewer = new GraphViewer(parent, SWT.BORDER);
		viewer.setContentProvider(new GraphNodeContentProvider());
		viewer.setLabelProvider(new GraphNodeLabelProvider());
		GraphNodeModelContentProvider model = new GraphNodeModelContentProvider();
		viewer.setInput(model.getNodes());
		LayoutAlgorithm layout = setLayout();
		viewer.setLayoutAlgorithm(layout, true);
		viewer.applyLayout();
		
	/*	viewer.addDoubleClickListener(new IDoubleClickListener() {
			
			@Override
			public void doubleClick(DoubleClickEvent event) {
				// TODO Auto-generated method stub
				logger.debug("ZEST 더블 클릭: " + event);
			}
		});*/
		
		fillToolBar();

		parent.setSize(700, model.displayHeightSize);
	}

	private LayoutAlgorithm setLayout() {
		LayoutAlgorithm layout;
		// layout = new
		// SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING);
		layout = new HorizontalTreeLayoutAlgorithm(
				LayoutStyles.NO_LAYOUT_NODE_RESIZING);
		// layout = new
		// GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING);
		// layout = new
		// HorizontalTreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING);
		// layout = new
		// RadialLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING);
		return layout;

	}

	/**
	 * Passing the focus request to the viewer's control.
	 */

	public void setFocus() {
	}

	private void fillToolBar() {
		/*
		 * ZoomContributionViewItem toolbarZoomContributionViewItem = new
		 * ZoomContributionViewItem( this); IActionBars bars =
		 * getViewSite().getActionBars();
		 * bars.getMenuManager().add(toolbarZoomContributionViewItem);
		 */
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// TODO Auto-generated method stub

	}

	@Override
	public void doSaveAs() {
		// TODO Auto-generated method stub

	}

	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		// Initialize the editor part

		logger.debug("site: " + site);
		logger.debug("site.getId: " + site.getId());
		logger.debug("input: " + input);

		if (!(input instanceof DashboardTableInput)) {
			throw new RuntimeException("Wrong input");
		}

		this.input = (DashboardTableInput) input;
		setSite(site);
		setInput(input);
		// proejctInfo =
		// MyModel.getInstance().getPersonById(this.input.getId());
		// setPartName("Person ID: " + proejctInfo.getId());
		setPartName("DASH BOARD");

	}

	@Override
	public boolean isDirty() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isSaveAsAllowed() {
		// TODO Auto-generated method stub
		return false;
	}

	/*
	 * @Override public AbstractZoomableViewer getZoomableViewer() { return
	 * viewer; }
	 */
}
